package com.pzhu.dormitory.controller;


import com.pzhu.dormitory.entity.RolePermissionRelationEntity;
import com.pzhu.dormitory.service.RolePermissionRelationService;
import com.pzhu.dormitory.utils.PageUtils;
import com.pzhu.dormitory.utils.R;
import com.pzhu.dormitory.utils.Rb;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;


/**
 * 后台用户角色和权限关系表
 *
 * @author
 * @email
 * @date 2021-04-10 08:46:25
 */
@Slf4j
@RestController
@Api(value = "RolePermissionRelationController", tags = "后台用户角色和权限关系表")
@RequestMapping("elective/rolepermissionrelation")
public class RolePermissionRelationController {
    @Autowired
    private RolePermissionRelationService rolePermissionRelationService;

    /**
     * 列表
     */
    @GetMapping("/list")
    @ApiOperation(value = "获取后台用户角色和权限关系表list")
    public R<RolePermissionRelationEntity> list(@RequestParam Map<String, Object> params) {
        PageUtils<RolePermissionRelationEntity> page = rolePermissionRelationService.queryPage(params);
        return Rb.a(RolePermissionRelationEntity.class).success().page(page).build();
    }


    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    @ApiOperation(value = "获取一个后台用户角色和权限关系表信息")
    public R<RolePermissionRelationEntity> info(@Validated @PathVariable("id") Long id) {
        RolePermissionRelationEntity rolePermissionRelation = rolePermissionRelationService.getById(id);
        return Rb.a(RolePermissionRelationEntity.class).success().withData(rolePermissionRelation).build();
    }

    /**
     * 保存
     */
    @ApiOperation(value = "保存后台用户角色和权限关系表信息")
    @PostMapping("/save")
    public R<RolePermissionRelationEntity> save(@Validated @RequestBody RolePermissionRelationEntity rolePermissionRelation) {
        rolePermissionRelationService.save(rolePermissionRelation);
        return Rb.a(RolePermissionRelationEntity.class).success().build();
    }

    /**
     * 修改
     */
    @ApiOperation(value = "更新后台用户角色和权限关系表信息")
    @PutMapping("/update")
    public R<RolePermissionRelationEntity> update(@RequestBody RolePermissionRelationEntity rolePermissionRelation) {
        rolePermissionRelationService.updateById(rolePermissionRelation);
        return Rb.a(RolePermissionRelationEntity.class).success().build();
    }

    /**
     * 删除
     */
    @ApiOperation(value = "删除后台用户角色和权限关系表信息")
    @DeleteMapping("/delete")
    public R<RolePermissionRelationEntity> delete(@RequestBody Long[] ids) {
        rolePermissionRelationService.removeByIds(Arrays.asList(ids));
        return Rb.a(RolePermissionRelationEntity.class).success().build();
    }

}
